package job.work.controller.system;

import job.work.domain.response.CommonCode;
import job.work.domain.response.ResponseResult;
import job.work.domain.system.entity.pojo.DecMenu;
import job.work.domain.system.request.MenuPageRequest;
import job.work.service.system.service.DecMenuService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * @author  2020-06-17
 */
@Api(tags = "菜单权限管理")
@RestController
@RequestMapping("/menu")
public class DecMenuController {
    @Resource
    private DecMenuService decMenuService;

    @GetMapping("/findAllMenu")
    @ApiOperation("查询所有菜单")
    public ResponseResult findAllMenu() {
        return decMenuService.findAllMenu();
    }

    @PostMapping("/findPageMenu")
    @ApiOperation("分页查询菜单")
    public ResponseResult selectAll(@Validated @RequestBody MenuPageRequest pageResultRequest) {
        return decMenuService.findPageMenu(pageResultRequest);
    }

    @PostMapping("/saveMenu")
    @ApiOperation("保存或者修改单个菜单")
    public ResponseResult saveMenu(@Validated @RequestBody DecMenu qmMenu) {
        return decMenuService.saveMenu(qmMenu);
    }



    @GetMapping("/findRoleMenu/{roleId}")
    @ApiOperation("根据角色ID查询菜单")
    public List<DecMenu> findRoleMenu(@PathVariable(value = "roleId") Long roleId) {
        return decMenuService.findRoleMenu(roleId);
    }


   @DeleteMapping("/delectBackgroundMenu/{id}")
   @ApiOperation("删除菜单")
   public ResponseResult delectBackgroundMenu(@PathVariable(value = "id") Long id) {
        if (id == null) {
            return new ResponseResult<>(CommonCode.PARAM_ERROR);
        }
        return decMenuService.delectMenu(id);
   }





}
